package win.larryzeal.spring.rmi.client;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.remoting.rmi.RmiProxyFactoryBean;
import win.larryzeal.spring.rmi.client.config.AppConfig;
import win.larryzeal.spring.rmi.common.service.HelloRMIService;

/**
 * Created by 张少昆 on 2017/8/23.
 */
public class ClientMain {

    public static void main(String[] args){
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
        //注意，这里是硬编码的port/url
        HelloRMIService bean = context.getBean(HelloRMIService.class);
        for(int i = 0; i < 10; ++i){
            System.out.println(bean.add(i, i * 3));
        }

        //注意，这里演示runtime实现
        RmiProxyFactoryBean proxy = new RmiProxyFactoryBean();
        proxy.setServiceUrl("rmi://localhost:9999/helloRMI");
        proxy.setServiceInterface(HelloRMIService.class);
        proxy.afterPropertiesSet();//必不可少
        HelloRMIService object = (HelloRMIService) proxy.getObject();
        System.out.println(object.add(99, 1999));
    }
}
